package com.lc.luzhengtang.activity;

import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.lc.luzhengtang.BaseApplication;
import com.lc.luzhengtang.R;
import com.lc.luzhengtang.adapter.EvaluateListAdapter;
import com.lc.luzhengtang.adapter.MyGridAdapter2;
import com.lc.luzhengtang.adapter.TagAdapter;
import com.lc.luzhengtang.banner.BannerLayout;
import com.lc.luzhengtang.base.BaseActivity;
import com.lc.luzhengtang.bean.CommenBean;
import com.lc.luzhengtang.bean.CommenCollectBean;
import com.lc.luzhengtang.bean.ShopDetailBean;
import com.lc.luzhengtang.conn.Conn;
import com.lc.luzhengtang.conn.ConnAddShop;
import com.lc.luzhengtang.conn.ConnShopCollect;
import com.lc.luzhengtang.conn.ConnShopDetail;
import com.lc.luzhengtang.conn.ConnShopDetailWeb;
import com.lc.luzhengtang.fragment.IndexWebActivity;

import com.lc.luzhengtang.pop.ShowPopuBuyOilCardPopu;
import com.lc.luzhengtang.util.LovelyToast;
import com.lc.luzhengtang.view.FlowTagLayout;
import com.lc.luzhengtang.view.GlideCircleTransform;
import com.lc.luzhengtang.view.NineGridTestModel;
import com.lc.luzhengtang.view.OnTagClickListener;
import com.lc.luzhengtang.view.ShowGoodsPropertyPopu;
import com.lc.luzhengtang.weigh.SlideDetailsLayout;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.scale.ScaleScreenHelperFactory;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.greenrobot.event.EventBus;

import static com.lc.luzhengtang.view.FlowTagLayout.FLOW_TAG_CHECKED_SINGLE;

/**
 * Created by Administrator on 2017/5/3.
 */
public class ShopDetailActivity_benfen extends BaseActivity implements SlideDetailsLayout.OnSlideDetailsListener, View.OnClickListener {

    @BindView(R.id.banner2)
    BannerLayout banner2;
    @BindView(R.id.web_view)
    WebView webView;
 /*   @BindView(R.id.ll_pull_up)
    LinearLayout llPullUp;*/

    @BindView(R.id.sv_switch)
    SlideDetailsLayout svSwitch;
    @BindView(R.id.text_title)
    TextView textTitle;
    @BindView(R.id.text_money)
    TextView textMoney;
    @BindView(R.id.text_order_pay)
    TextView textOrderPay;
    @BindView(R.id.text_xiaoliang)
    TextView textXiaoliang;
    @BindView(R.id.img_help)
    ImageView imgHelp;
    @BindView(R.id.search_all_payorder)
    RelativeLayout searchAllPayorder;
    @BindView(R.id.layout_commit)
    RelativeLayout layoutCommit;
    @BindView(R.id.rv_list)
    RecyclerView rvList;
    EvaluateListAdapter indexAdapter;
    List<ShopDetailBean.DataBeanX.EvaluateBean.DataBean> mDatas2;
    @BindView(R.id.joininshopcar)
    TextView joininshopcar;
    @BindView(R.id.img_btn_fanhiu)
    ImageView imgBtnFanhiu;
    @BindView(R.id.layout_collect)
    LinearLayout layoutCollect;
    @BindView(R.id.layout_shop)
    RelativeLayout layoutShop;
    @BindView(R.id.text_buyrightnow)
    TextView textBuyrightnow;
    @BindView(R.id.img_goto_shop)
    ImageView img_goto_shop;
    public static final String TURN_TO_CART="turn_to_cart";
    FlowTagLayout mColorFlowTagLayout;
    private ShowPopuBuyOilCardPopu cardPopu;
    private String shop_id;

    //商品iD
    String shangpin_id;
    private PopupWindow popWindow;
    private PopupWindow popWindow2;
    private TextView etname, tv01, tv02, tv03;

    private LinearLayout layout_dismiss;

    private TextView text_buyrightnow;

    private List<ShopDetailBean.DataBeanX.GoodsinfoBean> goodsinfoBeen;
    private String goodsType;
    private ShowGoodsPropertyPopu goodsPropertyPopu;

    List<String> goodsPropertyBeen;

    private static final String ARG_LIST = "list";

    private List<NineGridTestModel> mList1 = new ArrayList<>();
    LinearLayout ll_pull_up;
    MyGridAdapter2 myGridAdapter2;
    private TagAdapter<String> mColorTagAdapter;
    JSONObject jsonObj;
    private String text_title;
    String picurl;
    String sales;

    String title_sales;

    int num = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shopdetail);
        ButterKnife.bind(this);

        shop_id = getIntent().getStringExtra("goods_id");
        goodsinfoBeen = new ArrayList<>();
        Log.d(shop_id, "32222222222");
        goodsPropertyBeen = new ArrayList<>();

        ll_pull_up = (LinearLayout) findViewById(R.id.ll_pull_up);
        final View footView = getLayoutInflater()
                .inflate(R.layout.activity_list, null);
        final ListView listComment = (ListView) findViewById(R.id.list_comment);

        layoutCommit.addView(footView);

        final View footView2 = getLayoutInflater()
                .inflate(R.layout.item_slide, null);
//        listComment.addFooterView(footView2);

        for (int i = 0; i < 5; i++) {
            goodsPropertyBeen.add("1" + i);
        }
      /*  myGridAdapter2=new MyGridAdapter2(this,goodsPropertyBeen);
       listComment.setAdapter(myGridAdapter2);*/
        mDatas2 = new ArrayList<>();
        getData();
        rvList.setLayoutManager(new LinearLayoutManager(this));
        initAdapter();
//webview支持js
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        //支持插件
//设置自适应屏幕，两者合用
        webSettings.setUseWideViewPort(true); //将图片调整到适合webview的大小
        webSettings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小
//缩放操作
        webSettings.setSupportZoom(true); //支持缩放，默认为true。是下面那个的前提。
        webSettings.setBuiltInZoomControls(true); //设置内置的缩放控件。若为false，则该WebView不可缩放
        webSettings.setDisplayZoomControls(false); //隐藏原生的缩放控件

//其他细节操作
        webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); //关闭webview中缓存
        webSettings.setAllowFileAccess(true); //设置可以访问文件
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true); //支持通过JS打开新窗口
        webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片
        webSettings.setDefaultTextEncodingName("utf-8");//设置编码格式

        //   getData();
        getWebData();
        webView.loadUrl("http://luzhengtang.cn/index.php/api/goods/service?goods_id=" + shop_id);

        mColorTagAdapter = new TagAdapter<>(ShopDetailActivity_benfen.this);
        initColorData();

//        mAdapter = new NineGridTest2Adapter(this);

    }

    private void initColorData() {

    }

    @Override
    protected void onResume() {
        super.onResume();

    }

    public void getData() {
        new ConnShopDetail(shop_id, BaseApplication.basePreferences.readUid(), 1, new AsyCallBack<ShopDetailBean>() {
            @Override
            public void onStart(int type) throws Exception {
                super.onStart(type);
                showLoading();
            }

            @Override
            public void onSuccess(String toast, int type, Object o, ShopDetailBean shopDetailBean) throws Exception {
                super.onSuccess(toast, type, o, shopDetailBean);
//                mDatas2 = shopDetailBean.getData().getEvaluate();
                mDatas2 = shopDetailBean.getData().getEvaluate().getData();
                if (mDatas2.isEmpty()) {
                    rvList.setVisibility(View.GONE);
//                    layoutContainrecycleview.setVisibility(View.GONE);
                }
                mDatas2.addAll(shopDetailBean.getData().getEvaluate().getData());
                text_title = shopDetailBean.getData().getGoodsinfo().getTitle();
                textTitle.setText(shopDetailBean.getData().getGoodsinfo().getTitle());
                textXiaoliang.setText(shopDetailBean.getData().getGoodsinfo().getInfo());
                textMoney.setText("￥" + shopDetailBean.getData().getGoodsinfo().getSales());
                sales = shopDetailBean.getData().getGoodsinfo().getSales();
                //  shangpin_id = shopDetailBean.getData().getGoodsinfo().getId() + "";
                textOrderPay.setText("运费：" + shopDetailBean.getData().getGoodsinfo().getPostage()+"元");
                textXiaoliang.setText("销量：" + shopDetailBean.getData().getGoodsinfo().getVolume());

                title_sales = shopDetailBean.getData().getGoodsinfo().getSales();


                indexAdapter = new EvaluateListAdapter(mDatas2);
                indexAdapter.openLoadAnimation(BaseQuickAdapter.SCALEIN);
                rvList.setAdapter(indexAdapter);
                rvList.addOnItemTouchListener(new OnItemClickListener() {
                    @Override
                    public void onSimpleItemClick(final BaseQuickAdapter adapter, final View view, final int position) {
                        Toast.makeText(ShopDetailActivity_benfen.this, Integer.toString(position), Toast.LENGTH_LONG).show();
                    }
                });
                List<String> urls = new ArrayList<>();
                final List<String> urlspic = new ArrayList<String>();
                urls = shopDetailBean.getData().getGoodsinfo().getPicarr();
                for (int i = 0; i < urls.size(); i++) {
                    urlspic.add(Conn.HOST2 + urls.get(i));
                }

                picurl = shopDetailBean.getData().getGoodsinfo().getPicarr().get(0);
 ;
                banner2.setViewUrls(urlspic);
                final List<String> finalUrls = urls;
                banner2.setOnBannerItemClickListener(new BannerLayout.OnBannerItemClickListener() {
                    @Override
                    public void onItemClick(int position) {
                        //Toast.makeText(ShopDetailActivity.this, String.valueOf(position), Toast.LENGTH_SHORT).show();

                        Intent intent = new Intent();

                        //intent.putExtra("url", urlspic.get(position));
                        intent.putStringArrayListExtra("mImages", (ArrayList<String>) urlspic);
                        intent.setClass(ShopDetailActivity_benfen.this, PhotoShowActivity.class);
//                        startActivity(intent);

                    }
                });


            }

            @Override
            public void onFail(String toast, int type) throws Exception {
                super.onFail(toast, type);
                dismissLoading();
            }

            @Override
            public void onEnd(String toast, int type) throws Exception {
                super.onEnd(toast, type);
                dismissLoading();
            }
        }


        ).execute(ShopDetailActivity_benfen.this, false);
    }


    private void initAdapter() {

    }

    @Override
    public void onStatucChanged(SlideDetailsLayout.Status status) {
        if (status == SlideDetailsLayout.Status.OPEN) {
            //当前为图文详情页


        } else {
            //当前为商品详情页


        }
    }


    @OnClick({R.id.text_title, R.id.text_money, R.id.text_order_pay, R.id.text_xiaoliang, R.id.img_help, R.id.layout_commit, R.id.rv_list, R.id.joininshopcar, R.id.img_btn_fanhiu, R.id.layout_collect, R.id.layout_shop, R.id.text_buyrightnow, R.id.search_all_payorder, R.id.img_goto_shop})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_pull_up:
                svSwitch.smoothOpen(true);
                break;
            case R.id.text_title:
                break;
            case R.id.text_money:
                break;
            case R.id.text_order_pay:
                break;
            case R.id.text_xiaoliang:
                break;
            case R.id.img_help:
                Intent intent = new Intent();
                intent.putExtra("url", "http://luzhengtang.cn/index.php/api/index/service?web_id=2");
                intent.putExtra("flag", "2");
                intent.setClass(ShopDetailActivity_benfen.this, IndexWebActivity.class);
                startActivity(intent);

                break;
            case R.id.layout_commit:
                //    startActivity(new Intent(ShopDetailActivity.this, CommentAllActivity2.class));
                List<String> evaluate;

                Intent intent1 = new Intent();
                intent1.putExtra("shangpin_id", shop_id);
                intent1.setClass(ShopDetailActivity_benfen.this, CommentAllActivity2.class);
                startActivity(intent1);
                break;
            case R.id.rv_list:
                break;
            case R.id.joininshopcar:
                showPopupWindow(joininshopcar);
//                showPopu(0);
                break;

            case R.id.img_btn_fanhiu:
                finish();
                break;
            case R.id.layout_collect:
                getCollect();

                break;
            case R.id.layout_shop:
                break;

            case R.id.text_buyrightnow:
//                startActivity(new Intent(ShopDetailActivity.this, ConfirmOrderActivity2.class));

                showPopupWindow2(textBuyrightnow);


                break;

            case R.id.search_all_payorder:
                svSwitch.smoothOpen(true);
                break;


            case R.id.img_goto_shop:
             /*   LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(new Intent(TURN_TO_CART));
                startVerifyActivity(MainActivity.class);
                ShopDetailActivity.this.finish();*/
                LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(new Intent(TURN_TO_CART));
                ShopDetailActivity_benfen.this.finish();
                break;


        }
    }


    public void getCollect() {
        new ConnShopCollect(BaseApplication.basePreferences.readUid(), shop_id, new AsyCallBack<CommenCollectBean>() {
            @Override
            public void onSuccess(String toast, int type, Object o, CommenCollectBean commenBean) throws Exception {
                super.onSuccess(toast, type, o, commenBean);

                LovelyToast.makeText(ShopDetailActivity_benfen.this, commenBean.getMessage(), 0, LovelyToast
                        .SUCCESS, LovelyToast.SCALE);

            }


            @Override
            public void onFail(String toast, int type) throws Exception {
                super.onFail(toast, type);
            }

            @Override
            public void onEnd(String toast, int type) throws Exception {
                super.onEnd(toast, type);
            }
        }

        ).execute(ShopDetailActivity_benfen.this, false);
    }


    public void getWebData() {
        new ConnShopDetailWeb(shop_id, new AsyCallBack<CommenBean>() {
            @Override
            public void onSuccess(String toast, int type, Object o, CommenBean commenBean) throws Exception {
                super.onSuccess(toast, type, o, commenBean);

            }

            @Override
            public void onFail(String toast, int type) throws Exception {
                super.onFail(toast, type);
            }

            @Override
            public void onEnd(String toast, int type) throws Exception {
                super.onEnd(toast, type);
            }
        }

        ).execute(ShopDetailActivity_benfen.this, false);
    }

    private void showPopupWindow2(View parent) {
        if (popWindow2 == null) {

            View view1 = BoundViewHelper.boundView(this, ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) LayoutInflater.from(this)
                    .inflate(R.layout.pop_select_photo3, null)));

            //LayoutParams相当于一个Layout的信息包，它封装了Layout的位置、高、宽等信息。
            popWindow2 = new PopupWindow(view1, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
            initPop2(view1);
        }
        //设置动画效果
        popWindow2.setAnimationStyle(android.R.style.Animation_InputMethod);
        //获取popwindow焦点
        popWindow2.setFocusable(true);
        //设置popwindow如果点击外面区域，便关闭。
        popWindow2.setOutsideTouchable(true);
        popWindow2.setBackgroundDrawable(new BitmapDrawable());
        //实现软键盘不自动弹出,ADJUST_RESIZE属性表示Activity的主窗口总是会被调整大小，从而保证软键盘显示空间。
        popWindow2.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        //设置popwindow显示位置
        popWindow2.showAtLocation(parent, Gravity.CENTER, 0, 0);
    }

    public void initPop2(View view1) {
       /**/
        mColorFlowTagLayout = (FlowTagLayout) view1.findViewById(R.id.color_flow_layout);
        TextView tv_02 = (TextView) view1.findViewById(R.id.tv_02);
        tv_02.setText("￥" + title_sales);
        ImageView img_pic = (ImageView) view1.findViewById(R.id.img_pic);


//        Glide.with(ShopDetailActivity.this).load(Conn.HOST3 + getIntent().getStringExtra("img_url")).crossFade().error(R.mipmap.ic_launcher).into(img_pic);
        Glide.with(ShopDetailActivity_benfen.this)
                .load(Conn.HOST3 + getIntent().getStringExtra("img_url"))
                .transform(new GlideCircleTransform(ShopDetailActivity_benfen.this))
                .error(R.mipmap.zhanwei)
                .placeholder(R.mipmap.zhanwei)
                .into(img_pic);
        TextView tv_01 = (TextView) view1.findViewById(R.id.tv_01);
        tv_01.setText(text_title);
//购买的
        TextView tv_03 = (TextView) view1.findViewById(R.id.tv_03);
        if (TextUtils.isEmpty(BaseApplication.basePreferences.readUid())) {
            startActivity(new Intent(ShopDetailActivity_benfen.this, LoginActivity.class));
        } else {
            tv_03.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
              /*  Intent intent2 = new Intent();
                intent2.putExtra("cart_id", shop_id);
                intent2.setClass(ShopDetailActivity.this, ConfirmOrderActivity3.class);
                startActivity(intent2);*/
                    Intent intent2 = new Intent();
                    intent2.putExtra("cart_id", shop_id);
                    intent2.putExtra("num", num + "");
                    intent2.putExtra("he", "盒");
                    intent2.setClass(ShopDetailActivity_benfen.this, ConfirmOrderActivity3.class);
                    startActivity(intent2);
            /*        new ConnBuyNow(BaseApplication.basePreferences.readUid(), shop_id, num + "", "盒", new AsyCallBack<BuyRightnow>(){
                        @Override
                        public void onStart(int type) throws Exception {
                            super.onStart(type);
                        }

                        @Override
                        public void onSuccess(String toast, int type, Object o, BuyRightnow buyRightnow) throws Exception {
                            super.onSuccess(toast, type, o, buyRightnow);
                            LovelyToast.makeText(ShopDetailActivity.this, buyRightnow.getMessage(), 0, LovelyToast
                                    .SUCCESS, LovelyToast.SCALE);

                        }


                        @Override
                        public void onEnd(String toast, int type) throws Exception {
                            super.onEnd(toast, type);
                        }

                        @Override
                        public void onFail(String toast, int type) throws Exception {
                            super.onFail(toast, type);
                        }
                    }



                    ).execute(ShopDetailActivity.this, false);
*/

                }
            });
        }


        mColorTagAdapter = new TagAdapter<>(this);
        //颜色
//        mColorTagAdapter = new TagAdapter<>(this);
        List<String> dataSource = new ArrayList<>();
        dataSource.add("红色");
        dataSource.add("黑色");
        dataSource.add("花边色");
        mColorTagAdapter.onlyAddAll(dataSource);
        mColorFlowTagLayout.setAdapter(mColorTagAdapter);
        mColorFlowTagLayout.setTagCheckedMode(FLOW_TAG_CHECKED_SINGLE);
        mColorFlowTagLayout.setOnTagClickListener(new OnTagClickListener() {
            @Override
            public void onItemClick(FlowTagLayout parent, View view, int position) {
                Snackbar.make(view, "颜色:" + parent.getAdapter().getItem(position), Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

        layout_dismiss = (LinearLayout) view1.findViewById(R.id.layout_dismiss);
        layout_dismiss.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow2.dismiss();
            }
        });

        final TextView text_num = (TextView) view1.findViewById(R.id.text_num);

        //修改数量
        LinearLayout layout_countjia = (LinearLayout) view1.findViewById(R.id.layout_countjia);
        layout_countjia.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                num = num + 1;
                text_num.setText(num + "");
            }
        });
        LinearLayout layout_jian = (LinearLayout) view1.findViewById(R.id.layout_jian);
        if (num < 0) {
            LovelyToast.makeText(ShopDetailActivity_benfen.this, "商品数量不能为负数", 0, LovelyToast
                    .SUCCESS, LovelyToast.SCALE);
        } else {
            layout_jian.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (num < 1) {

                    } else {
                        num = num - 1;
                        text_num.setText(num + "");
                    }

                }
            });

        }

    }


    private void showPopupWindow(View parent) {
        if (popWindow == null) {
         /*   View view = LayoutInflater.from(this)
                    .inflate(R.layout.pop_select_photo2, null);*/
            View view = BoundViewHelper.boundView(this, ScaleScreenHelperFactory.getInstance().loadView((ViewGroup) LayoutInflater.from(this)
                    .inflate(R.layout.pop_select_photo2, null)));

            //LayoutParams相当于一个Layout的信息包，它封装了Layout的位置、高、宽等信息。
            popWindow = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
            initPop(view);
        }
        //设置动画效果
        popWindow.setAnimationStyle(android.R.style.Animation_InputMethod);
        //获取popwindow焦点
        popWindow.setFocusable(true);
        //设置popwindow如果点击外面区域，便关闭。
        popWindow.setOutsideTouchable(true);
        popWindow.setBackgroundDrawable(new BitmapDrawable());
        //实现软键盘不自动弹出,ADJUST_RESIZE属性表示Activity的主窗口总是会被调整大小，从而保证软键盘显示空间。
        popWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        //设置popwindow显示位置
        popWindow.showAtLocation(parent, Gravity.CENTER, 0, 0);
    }

    public void initPop(View view) {

        mColorFlowTagLayout = (FlowTagLayout) view.findViewById(R.id.color_flow_layout);

        mColorTagAdapter = new TagAdapter<>(this);
        //颜色
//        mColorTagAdapter = new TagAdapter<>(this);
        List<String> dataSource = new ArrayList<>();
        dataSource.add("红色");
        dataSource.add("黑色");
        dataSource.add("花边色");

        mColorTagAdapter.onlyAddAll(dataSource);
        mColorFlowTagLayout.setAdapter(mColorTagAdapter);
        mColorFlowTagLayout.setTagCheckedMode(FLOW_TAG_CHECKED_SINGLE);
        mColorFlowTagLayout.setOnTagClickListener(new OnTagClickListener() {
            @Override
            public void onItemClick(FlowTagLayout parent, View view, int position) {
                Snackbar.make(view, "颜色:" + parent.getAdapter().getItem(position), Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

        layout_dismiss = (LinearLayout) view.findViewById(R.id.layout_dismiss);
        layout_dismiss.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popWindow.dismiss();
            }
        });
        TextView tv_02 = (TextView) view.findViewById(R.id.tv_02);

        tv_02.setText("￥" + title_sales);
        ImageView img_pic = (ImageView) view.findViewById(R.id.img_pic);
//
//        Glide.with(ShopDetailActivity.this).load(Conn.HOST3 + getIntent().getStringExtra("img_url")).crossFade().error(R.mipmap.ic_launcher).into(img_pic);
        Glide.with(ShopDetailActivity_benfen.this)
                .load(Conn.HOST3 + getIntent().getStringExtra("img_url"))
                .transform(new GlideCircleTransform(ShopDetailActivity_benfen.this))
                .error(R.mipmap.zhanwei)
                .placeholder(R.mipmap.zhanwei)
                .into(img_pic);
        TextView tv_01 = (TextView) view.findViewById(R.id.tv_01);
        tv_01.setText(text_title);

        final TextView text_num = (TextView) view.findViewById(R.id.text_num);


        //修改数量
        LinearLayout layout_countjia = (LinearLayout) view.findViewById(R.id.layout_countjia);
        layout_countjia.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                num = num + 1;
                text_num.setText(num + "");
            }
        });

        LinearLayout layout_jian = (LinearLayout) view.findViewById(R.id.layout_jian);
        if (num < 0) {
            LovelyToast.makeText(ShopDetailActivity_benfen.this, "商品数量不能为负数", 0, LovelyToast
                    .SUCCESS, LovelyToast.SCALE);
        } else {
            layout_jian.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                 /*   num=num-1;
                    text_num.setText(num + "");*/
                    if (num < 1) {

                    } else {
                        num = num - 1;
                        text_num.setText(num + "");
                    }

                }
            });

        }

        //加入购物车
        TextView tv_03 = (TextView) view.findViewById(R.id.tv_03);

        if (TextUtils.isEmpty(BaseApplication.basePreferences.readUid())) {
            startActivity(new Intent(ShopDetailActivity_benfen.this, LoginActivity.class));
        }

        tv_03.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                new ConnAddShop(shop_id, BaseApplication.basePreferences.readUid(), num + "", "盒", title_sales, new AsyCallBack<CommenBean>() {
                    @Override
                    public void onStart(int type) throws Exception {
                        super.onStart(type);
                    }

                    @Override
                    public void onSuccess(String toast, int type, Object o, CommenBean commenBean) throws Exception {
                        super.onSuccess(toast, type, o, commenBean);
                        LovelyToast.makeText(ShopDetailActivity_benfen.this, commenBean.getMessage(), 0, LovelyToast
                                .SUCCESS, LovelyToast.SCALE);
                    }

                    @Override
                    public void onFail(String toast, int type) throws Exception {
                        super.onFail(toast, type);
                    }

                    @Override
                    public void onEnd(String toast, int type) throws Exception {
                        super.onEnd(toast, type);
                    }
                }


                ).execute(ShopDetailActivity_benfen.this, false);


            }
        });

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rl_ensure_digital:
                Toast.makeText(context, "加入购物车", Toast.LENGTH_SHORT).show();
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(ShopDetailActivity_benfen.this);
    }
}
